home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_07
/
allison
/
destroy4.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-02
|
677b
|
47 lines
LISTING 8 - Deallocates a resource in the midst of handling an
exception
// destroy4.cpp
#include <stdio.h>
void f(char *fname);
main()
{
try
{
f("file1.dat");
}
catch(...)
{
puts("Exception caught in main()");
}
return 0;
}
void f(char *fname)
{
FILE *fp = fopen(fname,"r");
if (fp)
{
try
{
throw 1;
}
catch (...)
{
fclose(fp);
puts("File closed");
throw; // Re-throw
}
fclose(fp); // The normal close
}
}
/* Output:
File closed
Excepion caught in main()
*/